package com.aitoedu.server.controller.student;

import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import com.aitoedu.server.entity.Student;
import com.aitoedu.server.service.StudentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/student")
@Slf4j
@CrossOrigin
@Tag(name = "学生端相关接口")
@SaCheckRole("学生")
public class StudentController {

    @Autowired
    private StudentService studentService;
    @Autowired
    private RedisTemplate redisTemplate;

    @GetMapping("/pl")
    @Operation(summary = "个人信息")
    public SaResult pl(){
        Long id = Long.valueOf(StpUtil.getLoginId().toString());
        Student student = (Student) redisTemplate.opsForValue().get("student_pl:"+id);
        if(student!=null) return SaResult.ok().setData(student);
        student = studentService.pl();
        redisTemplate.opsForValue().set("student_pl:"+id,student);
        return SaResult.ok().setData(student);
    }

}
